import tkinter as tk

class APP:     #定义APP类
    def __init__(self,master):
        frame = tk.Frame(master) #框架  
        frame.pack(side=tk.LEFT,padx=10,pady=10)

        self.hi_there = tk.Button(frame,text='打招呼',fg='blue',bg='yellow',command=self.say_hi)
        self.hi_there.pack() #按钮

    def say_hi(self):
        print('Hello!')

root = tk.Tk()  #创建顶层窗口
app = APP(root) #实例化APP

root.mainloop() #进入主事件循环
